package com.example.designpattern.delegate;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @author long
 * @date 2024/11/16 21:58
 */
public enum CheckTypeEnum {

    FREE_CHECK(0,"免检"),

    SEND_CHECK(1,"送检");

    private Integer code;

    private String desc;

    CheckTypeEnum(Integer code,String desc){
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据code查询枚举值
     * @param code
     * @return
     */
    public static CheckTypeEnum getEnumByCode(Integer code){
        return Stream.of(values()).filter(e-> Objects.equals(e.code,code)).findFirst().orElse(null);
    }

    /**
     * 是否免检
     * @param code
     * @return
     */
    public static boolean isFreeCheck(Integer code){
        return Objects.equals(code,CheckTypeEnum.FREE_CHECK.code);
    }

}
